using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnlineTigger : MonoBehaviour
{
    public GameObject gameSystem_gameObject;
    public GameObject uI_Input_Tip;
    bool init = false;
    GameSystem gameSystem;

    // Start is called before the first frame update
    void Start()
    {
        gameSystem = gameSystem_gameObject.GetComponent<GameSystem>();
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetButtonDown("Action") && init)
        {
            gameSystem.JoinInOnline();
        }
    }

    void OnTriggerEnter(Collider collision)
    {
        if (collision.transform.parent.gameObject.tag == "player" && collision.transform.parent.gameObject.name == gameSystem.getGameManager().user)
        {
            uI_Input_Tip.GetComponent<UI_Input_Tip>().Start("F 进入线上世界");
            init = true;
        }
    }

    void OnTriggerExit(Collider collision)
    {
        if (collision.transform.parent.gameObject.tag == "player" && collision.transform.parent.gameObject.name == gameSystem.getGameManager().user)
        {
            uI_Input_Tip.GetComponent<UI_Input_Tip>().Stop();
            init = false;
        }
    }
}
